package org.grottarossa.ui.core.components;

import java.util.HashMap;
import java.util.ResourceBundle;

import org.grottarossa.template.data.pojo.query.Query;
import org.grottarossa.template.drivers.DriverException;
import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.base.BasePanel;
import org.grottarossa.ui.core.i18n.DM;


import com.vaadin.terminal.ExternalResource;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window.Notification;
import com.vaadin.ui.Label;

public class QueryForwardPanel extends BasePanel
{

	/**
	 *
	 */
	private static final long serialVersionUID = 7039968590374205065L;

	public QueryForwardPanel(ApplicationSession appSession)
	{
		super(appSession, DM.instance().getBundle(QueryForwardPanel.class.getName()));
	}

	public void draw(String forwardPage, String scriptName, HashMap<String, String> params)
	{
		Query query = null;
		try
		{
			query = m_appSession.getBuilder().getCaseManagement().executeQuery(scriptName,params);
		}
		catch (DriverException e)
		{
			getWindow().showNotification(m_localizer.getString("panel.error")+" - "+
					e.getMessage(),
					Notification.TYPE_ERROR_MESSAGE);

			 Label preformattedText = new Label(m_localizer.getString("panel.error.label"));
			 preformattedText.setContentMode(Label.CONTENT_XHTML);
			 addComponent(preformattedText);
		}

		VerticalLayout layout = new VerticalLayout();
		layout.setSizeFull();

		Embedded e = new Embedded("", new ExternalResource(forwardPage));
		e.setType(Embedded.TYPE_BROWSER);
		e.setWidth("100%");
		e.setHeight("100%");
		layout.addComponent(e);
		this.setContent(layout);
	}

	@Override
	protected void initializeComponents() {
		// TODO Auto-generated method stub

	}
}